package pl.un4giv3n.mightvsmagic.entity;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 * @author andrzejewskia this is a template for the items, added by admin. This
 *         is shown on the bazar, and when users buy an item, it is used to
 *         create item instance
 */
@NamedQueries( {
		@NamedQuery(name = "find.all.itemtemplates", query = "select i from ItemTemplate i"),
		@NamedQuery(name = "find.user.avaible.itemtemplates", query = "select i from ItemTemplate i where requiredAnyExp " +
				"<= :userAnyExp and requiredMagicExp <= :userMagicExp and requiredFightExp <= :userFightExp and parryReq <= :userParry and attackReq <= :userAttack" +
				" and manaReq <= :userMana and staminaReq <= :userStamina and strenghtReq <= :userStrenght") 
})
@Entity
public class ItemTemplate implements Comparable<ItemTemplate> {

	/**
	 * id
	 */
	private Long id;
	/**
	 * item name
	 */
	private String name;
	/**
	 * item type
	 */
	@Enumerated(EnumType.STRING)
	private ItemType type;
	/**
	 * item image url
	 */
	private String imgUrl;
	/**
	 * item min def
	 */
	private double minDef;
	/**
	 * item max def
	 */
	private double maxDef;
	/**
	 * item min dmg
	 */
	private double minDmg;
	/**
	 * item max dmg
	 */
	private double maxDmg;
	/**
	 * item price
	 */
	private int price;
	private int premiumPrice;
	/**
	 * item modificatiors
	 */
	private long strenghtModifier;
	private long staminaModifier;
	private long manaModifier;
	private long attackModifier;
	private long parryModifier;
	private long speedModifier;

	/**
	 * item requirements
	 */
	private long strenghtReq;
	private long staminaReq;
	private long manaReq;
	private long attackReq;
	private long parryReq;
	private long requiredFightExp;
	private long requiredMagicExp;
	private long requiredAnyExp;

	public ItemTemplate() {
		super();
	}

	public ItemTemplate(String name, ItemType type, String imgUrl,
			double minDef, double maxDef, double minDmg, double maxDmg,
			int price, int premiumPrice, long requiredFightExp,
			long requiredMagicExp, long strenghtModifier, long staminaModifier,
			long manaModifier, long attackModifier, long parryModifier,
			long speedModifier, long strenghtReq, long staminaReq,
			long manaReq, long attackReq, long parryReq, long requiredAnyExp) {
		super();
		this.name = name;
		this.type = type;
		this.imgUrl = imgUrl;
		this.minDef = minDef;
		this.maxDef = maxDef;
		this.minDmg = minDmg;
		this.maxDmg = maxDmg;
		this.price = price;
		this.premiumPrice = premiumPrice;
		this.requiredFightExp = requiredFightExp;
		this.requiredMagicExp = requiredMagicExp;
		this.strenghtModifier = strenghtModifier;
		this.staminaModifier = staminaModifier;
		this.manaModifier = manaModifier;
		this.attackModifier = attackModifier;
		this.parryModifier = parryModifier;
		this.speedModifier = speedModifier;
		this.strenghtReq = strenghtReq;
		this.staminaReq = staminaReq;
		this.manaReq = manaReq;
		this.attackReq = attackReq;
		this.parryReq = parryReq;
		this.requiredFightExp = requiredFightExp;
		this.requiredMagicExp = requiredMagicExp;
		this.requiredAnyExp = requiredAnyExp;
	}

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getMinDef() {
		return minDef;
	}

	public void setMinDef(double minDef) {
		this.minDef = minDef;
	}

	public double getMaxDef() {
		return maxDef;
	}

	public void setMaxDef(double maxDef) {
		this.maxDef = maxDef;
	}

	public double getMinDmg() {
		return minDmg;
	}

	public void setMinDmg(double minDmg) {
		this.minDmg = minDmg;
	}

	public double getMaxDmg() {
		return maxDmg;
	}

	public void setMaxDmg(double maxDmg) {
		this.maxDmg = maxDmg;
	}

	public ItemType getType() {
		return type;
	}

	public void setType(ItemType type) {
		this.type = type;
	}

	void setId(Long id) {
		this.id = id;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public String getImgUrl() {
		return imgUrl;
	}

	public void setImgUrl(String imgUrl) {
		this.imgUrl = imgUrl;
	}

	public long getRequiredFightExp() {
		return requiredFightExp;
	}

	public void setRequiredFightExp(long requiredFightExp) {
		this.requiredFightExp = requiredFightExp;
	}

	public long getRequiredMagicExp() {
		return requiredMagicExp;
	}

	public void setRequiredMagicExp(long requiredMagicExp) {
		this.requiredMagicExp = requiredMagicExp;
	}

	public long getStrenghtModifier() {
		return strenghtModifier;
	}

	public void setStrenghtModifier(long strenghtModifier) {
		this.strenghtModifier = strenghtModifier;
	}

	public long getStaminaModifier() {
		return staminaModifier;
	}

	public void setStaminaModifier(long staminaModifier) {
		this.staminaModifier = staminaModifier;
	}

	public long getManaModifier() {
		return manaModifier;
	}

	public void setManaModifier(long manaModifier) {
		this.manaModifier = manaModifier;
	}

	public long getAttackModifier() {
		return attackModifier;
	}

	public void setAttackModifier(long attackModifier) {
		this.attackModifier = attackModifier;
	}

	public long getParryModifier() {
		return parryModifier;
	}

	public void setParryModifier(long parryModifier) {
		this.parryModifier = parryModifier;
	}

	public long getStrenghtReq() {
		return strenghtReq;
	}

	public void setStrenghtReq(long strenghtReq) {
		this.strenghtReq = strenghtReq;
	}

	public long getStaminaReq() {
		return staminaReq;
	}

	public void setStaminaReq(long staminaReq) {
		this.staminaReq = staminaReq;
	}

	public long getManaReq() {
		return manaReq;
	}

	public void setManaReq(long manaReq) {
		this.manaReq = manaReq;
	}

	public long getAttackReq() {
		return attackReq;
	}

	public void setAttackReq(long attackReq) {
		this.attackReq = attackReq;
	}

	public long getParryReq() {
		return parryReq;
	}

	public void setParryReq(long parryReq) {
		this.parryReq = parryReq;
	}

	public int getPremiumPrice() {
		return premiumPrice;
	}

	public void setPremiumPrice(int premiumPrice) {
		this.premiumPrice = premiumPrice;
	}

	@Override
	public int compareTo(ItemTemplate o) {
		long thisVal = this.requiredAnyExp;
		long anotherVal = o.requiredAnyExp;
		if (thisVal == 0 && anotherVal == 0) {
			thisVal = this.requiredFightExp + this.requiredMagicExp;
			anotherVal = o.requiredFightExp + o.requiredMagicExp;
		}
		if (thisVal == 0 && anotherVal == 0) {
			thisVal = attackReq + parryReq + manaReq + staminaReq + strenghtReq
					+ requiredFightExp + requiredMagicExp;
			anotherVal = o.attackReq + o.parryReq + o.manaReq + o.staminaReq
					+ o.strenghtReq + o.requiredFightExp + o.requiredMagicExp;
		}
		return (thisVal < anotherVal ? 1 : (thisVal == anotherVal ? 0 : -1));
	}

	public long getSpeedModifier() {
		return speedModifier;
	}

	public void setSpeedModifier(long speedModifier) {
		this.speedModifier = speedModifier;
	}

	public long getRequiredAnyExp() {
		return requiredAnyExp;
	}

	public void setRequiredAnyExp(long requiredAnyExp) {
		this.requiredAnyExp = requiredAnyExp;
	}

}
